import java.util.StringTokenizer;

class P531 {

    public static void main(String[] args) {
        String line = readLn();
        while (line != null) {
            String line1 = line;
            line1 = readMore(line1);
            String line2 = "";
            line2 = readMore(line2);

            int answer = process(line1.trim(), line2.trim());
            line = readLn();
        }
    }


    private static String readMore(String line) {
        String answer = "";
        if (line.equals("#")) {
            return answer;
        } else {
            answer += line;
        }
        line = readLn();
        while (!line.equals("#")) {
            answer += " " + line;
            line = readLn();
        }
        
        return answer;
    }


    private static int process(String line1, String line2) {
        StringTokenizer st = new StringTokenizer(line1);
        String[] word1 = new String[st.countTokens()];
        for (int k = 0; k < word1.length; k++) {
            word1[k] = st.nextToken();
        }
        
        st = new StringTokenizer(line2);
        String[] word2 = new String[st.countTokens()];
        for (int k = 0; k < word2.length; k++) {
            word2[k] = st.nextToken();
        }

        
        int x = word1.length + 1;
        int y = word2.length + 1;
        
        int[][] counter = new int[x][y];
        
        for (int k = 0; k < x; k++) {
            counter[k][0] = 0;
        }
        
        for (int k = 0; k < y; k++) {
            counter[0][k] = 0;
        }
        
        for (int k = 1; k < y; k++) {
            for (int j = 1; j < x; j++) {
                counter[j][k] = maxOf(counter[j][k-1], counter[j-1][k]);
                if (word1[j-1].equals(word2[k-1])) {
                    counter[j][k] = counter[j-1][k-1]+1;
                }
            }
        }
        
        x = word1.length;
        y = word2.length;
        
        int cursor = counter[x][y];
        
        String answerStr = "";
        
        while (cursor > 0) {
            if (cursor == counter[x-1][y]) {
                cursor = counter[x-1][y];
                x = x -1;
            } else if (cursor == counter[x][y-1]){
                cursor = counter[x][y-1];
                y = y - 1;
            } else {
                cursor = counter[x-1][y-1];
                x = x - 1;
                y = y - 1;
                answerStr = word1[x] + " " + answerStr;
            }
        }
        
        System.out.println(answerStr.trim());
        return counter[word1.length][word2.length];
    }

    private static int maxOf(int i, int j) {
        return  i > j ? i : j;
    }


    static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString());
    }

    private static boolean isNumber(int car) {
        int carMin = (int) car;
        if ((carMin >= 48) && (carMin <= 57)) {
            return true;
        }
        return false;
    }

    
    private static boolean isLetter(int car) {
        char c = Character.toLowerCase((char)car);
        int carMin = (int)c;
        if ((carMin >= 97) && (carMin <= 122)) {
            return true;
        }
        return false;
    }
 
    
}